#/bin/bash
#2020-05-13

#System 
if [ -e /etc/redhat-release ]; then
    OS=CentOS
	Command="yum install -y epel-release tor net-tools"
   [ -n "$(grep ' 7\.' /etc/redhat-release 2> /dev/null)" ] && OS_Ver=7
   [ -n "$(grep ' 6\.' /etc/redhat-release 2> /dev/null)" ] && OS_Ver=6
  elif [ -n "$(grep -i 'Debian' /etc/issue 2> /dev/null)" ]; then
    OS=Debian
	Command="apt-get -y update && apt-get -y install epel-release tor net-tools"
	echo '[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
 
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
 
[Install]
WantedBy=multi-user.target' >/etc/systemd/system/rc-local.service
systemctl enable rc-local && systemctl start rc-local.service

  elif [ -n "$(grep -i 'Ubuntu' /etc/issue 2> /dev/null)" ]; then
    OS=Ubuntu
	Command="apt-get -y install epel-release tor net-tools"
	echo "[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
 
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
 
[Install]
WantedBy=multi-user.target" >/etc/systemd/system/rc-local.service
systemctl enable rc-local && systemctl start rc-local.service
  else
    echo "UnknownOS"	
 	exit
fi
echo -e "\033[32m $OS $OS_Ver \033[0m"
$Command
echo -e "\033[32m Create user: \033[0m"
useradd tor -d /home/tor
chown -R tor:tor /home/tor && chown -R tor:tor /var/run/tor
chown -R tor:tor /etc/tor  && chown -R tor:tor /run/tor
su - tor -c "/usr/bin/tor >>/etc/tor/tor.log&"
chmod 777 /etc/tor/tor.log
echo 'su - tor -c "/usr/bin/tor >>/etc/tor/tor.log&"' >>/etc/rc.local
chmod 755 /etc/rc.local 
netstat -lnet|grep 9050
echo -e "\033[32m Done. \033[0m"